package com.deer.wms.intercept.security;

import com.deer.wms.project.root.util.MD5Utils;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @author : wei
 * @since : 2021-07-28 17:30:48
 **/
@Component
public class DefaultPasswordEncoder implements PasswordEncoder {

    public DefaultPasswordEncoder() {
        this(-1);
    }

    public DefaultPasswordEncoder(int strength) {

    }

    /**
     * MD5
     */
    @Override
    public String encode(CharSequence charSequence) {
        return MD5Utils.encryptPassword(charSequence.toString());
    }


    @Override
    public boolean matches(CharSequence charSequence, String encodedPassword) {
        String[] splitStr = encodedPassword.split(",");
        encodedPassword = splitStr[0];
        String account = splitStr[1];
        String salt = splitStr[2];
        return encodedPassword.equals(MD5Utils.encryptPassword(account, charSequence.toString(), salt));
    }
}
